package com.example.first;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

public class MyListActivity extends ListActivity{
    String TAG="MyListActivity";
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: ");
        List<String> list1 = new ArrayList<String>();
        for(int i=1;i<100;i++){
            list1.add("item"+i);
        }
        String[] list_data={"one","two","three","four"};
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list1);
        setListAdapter(adapter);
        //getListView().setOnItemClickListener(this);//父类为listactivity
//        String[] list_data={"one","two","three","测试"};
//        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list_data);
//        mylist.setAdapter(adapter);
        handler = new Handler(Looper.myLooper()) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 5) {
                    List<String> list2=(List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(MyListActivity.this, android.R.layout.simple_list_item_1,list2);
                    setListAdapter(adapter);
                    Log.i(TAG, "onon: ");
                }
                super.handleMessage(msg);
            }
        };
        MyTask mytask=new MyTask();
        mytask.setHandler(handler);
        Thread t = new Thread(mytask);
        t.start();
    }

}